import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Hashtable;

/**
 * @author mjy(建立连接——数据传输…（保持连接）…数据传输——关闭连接)
 * @date 2021/10/26
 * @description
 */
public class TCPTransport {

    private  static  final  int SERVER_PORT=8883;

    private static Hashtable<String, Socket> ht = new Hashtable();

    public static void main(String[] args) throws IOException {
        System.out.println("VNTCenter.main()===TCP SERVER==============");
        //新建
        ServerSocket    vntServer=null;
        try {
            //监听本机的端口的地址是否有连接
            vntServer=new ServerSocket(SERVER_PORT);
            System.out.println("监听的端口"+vntServer.getLocalPort()+"...");
            while (true){
                //一旦建立连接就会被监听到
                Socket vntClient = vntServer.accept();
                System.out.println("客户IP "+vntClient.getInetAddress()+"...");
                System.out.println("客户端口 "+vntClient.getPort()+"...");
                //新建线程
                new GetGpsThreadFun(vntClient).start();
                //进客户端ip转为String字符串，存到map中
                ht.put(vntClient.getInetAddress().toString(),vntClient);
            }

        } catch (IOException e) {
            e.printStackTrace();
            //异常关闭
            vntServer.close();
        }


    }



}
